package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.EcologyCastConf;
import com.sc.nft.entity.EcologyReforgeConf;
import com.sc.nft.entity.vo.AdminSimpleReforgeCollectionVO;
import com.sc.nft.entity.vo.ecology.AdminGetPageReforgeConfVO;
import com.sc.nft.entity.vo.ecology.EcologyReforgeDetailsVO;
import com.sc.nft.entity.vo.ecology.EcologyReforgeListVO;
import com.sc.nft.mapper.EcologyReforgeConfMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Author：LiGen
 * @Package：com.sc.nft.dao
 * @Project：sc_metago
 * @name：EcologyReforgeCastConfDao
 * @Date：2024/6/14 17:45
 * @Filename：EcologyReforgeCastConfDao
 */
@Slf4j
@Repository
public class EcologyReforgeConfDao extends ServiceImpl<EcologyReforgeConfMapper, EcologyReforgeConf> {
    public EcologyReforgeConf getOneByCollectionId(Long collectionId) {
        LambdaQueryWrapper<EcologyReforgeConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyReforgeConf::getCollectionId, collectionId);
        wrapper.orderByDesc(EcologyReforgeConf::getId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public boolean updateSortById(Long id, Long sort) {
        LambdaUpdateWrapper<EcologyReforgeConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(EcologyReforgeConf::getSort, sort);
        wrapper.eq(EcologyReforgeConf::getId, id);
        return update(new EcologyReforgeConf(), wrapper);
    }

    public Page<AdminGetPageReforgeConfVO> getPageReforgeConf(String collectionName, Integer pageNo, Integer pageSize) {
        return baseMapper.getPageReforgeConf(new Page<>(pageNo, pageSize), collectionName);
    }

    public boolean updateStatusById(Long id, Boolean status) {
        LambdaUpdateWrapper<EcologyReforgeConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(EcologyReforgeConf::getStatus, status);
        wrapper.eq(EcologyReforgeConf::getId, id);
        return update(new EcologyReforgeConf(), wrapper);
    }

    public boolean updateSortAndRefluxRatioById(Long id, Long sort, BigDecimal refluxRatio, Integer reforgeFreeCount,
                                                Boolean isReforgeCondition, Long conditionCollectionId, String conditionCollectionName) {
        LambdaUpdateWrapper<EcologyReforgeConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(EcologyReforgeConf::getSort, sort);
        wrapper.set(EcologyReforgeConf::getRefluxRatio, refluxRatio);
        wrapper.set(EcologyReforgeConf::getReforgeFreeCount, reforgeFreeCount);
        wrapper.set(EcologyReforgeConf::getIsReforgeCondition, isReforgeCondition);
        wrapper.set(EcologyReforgeConf::getConditionCollectionId, conditionCollectionId);
        wrapper.set(EcologyReforgeConf::getConditionCollectionName, conditionCollectionName);
        wrapper.eq(EcologyReforgeConf::getId, id);
        return update(new EcologyReforgeConf(), wrapper);
    }

    public boolean delReforgeConfById(Long id) {
        return this.lambdaUpdate()
                .eq(EcologyReforgeConf::getId, id)
                .remove();
    }

    public Page<AdminSimpleReforgeCollectionVO> getSimplePage(Integer pageNo, Integer pageSize) {
        return baseMapper.getSimplePage(new Page<>(pageNo, pageSize));
    }

    public List<EcologyReforgeConf> getListByStatus(Boolean status) {
        LambdaQueryWrapper<EcologyReforgeConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyReforgeConf::getStatus, status);
        return list(wrapper);
    }

    public Page<EcologyReforgeListVO> getPageEcologyReforge(Integer pageNo, Integer pageSize, List<Long> collectionIds,Long userCreatorId) {
        return baseMapper.getPageEcologyReforge(new Page<>(pageNo, pageSize), collectionIds,userCreatorId);
    }

    public EcologyReforgeDetailsVO getProductDetailsById(Long id) {
        return baseMapper.getProductDetailsById(id);
    }
}
